package com.repair.project.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.repair.project.config.R;
import com.repair.project.entity.Announce;
import com.repair.project.entity.Student;
import com.repair.project.entity.Worker;
import com.repair.project.service.AnnounceService;
import com.repair.project.service.WorkerService;
import com.sun.corba.se.impl.ior.WireObjectKeyTemplate;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hz
 * @since 2021-01-12
 */
@RestController
@RequestMapping("/project/worker")
public class WorkerController {
    @Autowired
    WorkerService workerService;

    @ApiOperation("接口描述：获取维修工人列表")
    @GetMapping("getWorkerList")
    public R getWorkerList(@RequestParam(value = "page")int page, @RequestParam(value = "limit")int limit,
                           @RequestParam(required = false, value = "wokerid")Integer wokerid,
                           @RequestParam(required = false, value = "name")String name,
                           @RequestParam(required = false, value = "statu")String statu){

        PageHelper.startPage(page,limit);
        List<Map<String,Object>> list = workerService.getWorkerList(wokerid,name,statu);
        PageInfo<Map<String,Object>> pageInfo = new PageInfo<Map<String,Object>>(list);
        Map<String,Object> data=new HashMap<>();//装载分页数据
        data.put("data",pageInfo.getList());//数据
        return R.ok().data("datalist",pageInfo);
    }

    @ApiOperation("接口描述:增加维修工人")
    @PostMapping("addWorker")
    public R addWorker(@RequestBody Worker worker){
        return R.ok().data("data",workerService.save(worker));
    }

    @ApiOperation("接口描述：删除维修工人")
    @GetMapping("delWorker")
    public R delWorker(@RequestParam(value = "workerid")int workerid){
        return R.ok().data("data",workerService.removeById(workerid));
    }

    @ApiOperation("接口描述：更新维修工人")
    @PostMapping("updWorker")
    public R updWorker(@RequestBody Worker worker){
        return R.ok().data("data",workerService.updateById(worker));
    }



}

